/*!
 * \file debug.c
 * \brief Fichier permettant la mise au point interactive.
 * \author RUL Mathieu
 * \version 1.0
 * \date 08 juin 2011
 */
#include <stdio.h>
#include "debug.h"

//! Buffer pour la lecture des commandes
#define SIZE_BUFF 100

bool debug_ask(Machine *pmach) {
	char cmd[SIZE_BUFF];
	bool result = true, quit = false;
	    
 	while (!quit) {
 		printf("DEBUG ? ");
 		fflush(stdout); 
  	    	fgets(cmd, SIZE_BUFF, stdin);

		switch (cmd[0]) {
		  case 'h':              
		    printf("Available commands:");
		    printf("\n\th\thelp");
		    printf("\n\tc\tcontinue (exit interactive debug mode)");
		    printf("\n\ts\tstep by step (next instruction)");
		    printf("\n\tRET\tstep by step (next instruction)");
		    printf("\n\tr\tprint registers");
		    printf("\n\td\tprint data memory");
		    printf("\n\tt\tprint text (program) memory");
		    printf("\n\tp\tprint text (program) memory");
		    printf("\n\tm\tprint registers and data memory\n");
		    break;
		  case 'c': 
		    result = false;
		    quit = true;
		    break;
		  case 's':
		  case '\n':
		    quit = true; 
		    break;
		  case 'r':
		    print_cpu(pmach);
		    break;
		  case 'd':
		    print_data(pmach);
		    break;
		  case 't':
		  case 'p':
		    print_program(pmach);
		    break;
		  case 'm':
		    print_cpu(pmach);
		    print_data(pmach);
		    break;
		  default:
		    break;
		}
	}
	return result;
}
